package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.MyMoney;

@Transactional(readOnly = true)
public interface MyMoneyRepository extends JpaRepository<MyMoney, String>{
	//所有
	@Query(" select a from MyMoney a where a.useContent like '%'+?1+'%' or a.applyUser like '%'+?1+'%' or a.creatUser like '%'+?1+'%' or a.memo like '%'+?1+'%' ")
	Page<MyMoney> getMoney(String key, Pageable pageable);
	
	@Query(" select count(*) from MyMoney a where a.useContent like '%'+?1+'%' or a.applyUser like '%'+?1+'%' or a.creatUser like '%'+?1+'%' or a.memo like '%'+?1+'%'  ")
	long getCount(String key);
	//本部门
	@Query(" select a from MyMoney a where (a.useContent like '%'+?1+'%' or a.applyUser like '%'+?1+'%' or a.creatUser like '%'+?1+'%' or a.memo like '%'+?1+'%') and a.applyDept = ?2")
	Page<MyMoney> getMoney(String key, String superior, Pageable pageable);
	
	@Query(" select count(*) from MyMoney a where (a.useContent like '%'+?1+'%' or a.applyUser like '%'+?1+'%' or a.creatUser like '%'+?1+'%' or a.memo like '%'+?1+'%' )  and a.applyDept = ?2  ")
	long getCount(String key, String superior);
	
	//本片区
	@Query(" select a from MyMoney a where (a.useContent like '%'+?1+'%' or a.applyUser like '%'+?1+'%' or a.creatUser like '%'+?1+'%' or a.memo like '%'+?1+'%') and a.applyArea = ?2  ")
	Page<MyMoney> getMoneySal(String key, String areaId, Pageable pageable);
	
	@Query(" select count(*) from MyMoney a where (a.useContent like '%'+?1+'%' or a.applyUser like '%'+?1+'%' or a.creatUser like '%'+?1+'%' or a.memo like '%'+?1+'%' ) and a.applyArea = ?2   ")
	long getCountSal(String key, String areaId);
}
